package com.skyz.wrap.dialog;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;

import com.skyz.base.dialog.BaseDialogFragment;
import com.skyz.wrap.R;

public class AuthPayDialogFragment extends BaseDialogFragment {

    public static AuthPayDialogFragment showDialogFragment(@NonNull FragmentManager manager,String price, PaymentClickListener listener) {
        AuthPayDialogFragment loadingDialogFragment = new AuthPayDialogFragment();
        loadingDialogFragment.config(price,listener);
        loadingDialogFragment.show(manager, null);
        return loadingDialogFragment;
    }

    PaymentClickListener listener;
    String price;

    private void config(String price,PaymentClickListener listener) {
        this.listener = listener;
        this.price = price;
    }

    public AuthPayDialogFragment() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_fragment_authpay;
    }

    private View click_cancle;
    private View click_ok;
    private TextView tv_price;

    @Override
    protected void onLayoutInflated(View view) {

        click_ok = view.findViewById(R.id.click_ok);
        click_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null) {
                    listener.onOk();
                }
            }
        });
        click_cancle = view.findViewById(R.id.click_cancle);
        click_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener != null) {
                    listener.onCancel();
                }
            }
        });
        tv_price = view.findViewById(R.id.tv_price);
        tv_price.setText(TextUtils.isEmpty(price)?"0":price);
        setDialogCancelable(false);
    }

    @Override
    protected WindowManager.LayoutParams initLayoutParams(WindowManager.LayoutParams layoutParams) {
        layoutParams.gravity = Gravity.CENTER;
        layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        return layoutParams;
    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    public interface PaymentClickListener{
        void onOk();
        void onCancel();
    }
}
